package com.hq.api;

import com.hq.pojo.Admin;
import com.hq.pojo.Custome;
import com.hq.pojo.Staff_message;
import com.hq.pojo.Staff_work;
import com.hq.service.Staff_workService;
import com.hq.utils.MassageJson;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/staff_w")
public class Staff_workApi {
    @Resource
    Staff_workService staff_workService;
//增
    @RequestMapping(value = "/addStaff_work",method = RequestMethod.POST)
    public MassageJson addAStaff_work(@RequestBody  Staff_work staff_work){

        int i = 0;
        try{
            System.out.println("接受到的"+staff_work);
            i = staff_workService.ins_staff_work(staff_work);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i>0){
            return new MassageJson(200,"添加成功",1);
        }else {
            return new MassageJson(201,"添加失败",0);
        }

    }
    //删
    @RequestMapping(value = "/delStaff_work",method = RequestMethod.POST)
    public MassageJson delStaff_work(int staff_id){
        int i = 0;
        try{
            i = staff_workService.del_staff_work(staff_id);
            System.out.println("删除员工工作信息，员工id是"+staff_id);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(i>0){
            return  new MassageJson(200,"删除成功",i);
        }else {
            return  new MassageJson(201,"删除失败",i);
        }
    }
//根据Staff_id查
    @RequestMapping(value = "/getStaff_work",method = RequestMethod.POST)
    public MassageJson getStaff_work(@RequestBody Staff_work staff_work){
        System.out.println(staff_work);
        List<Staff_work> staff_workslist = null;
        long a = staff_work.getStaff_id();
        int s_id =  (int)a;
        Integer sss = s_id;
        //定义空对象
        System.out.println("触发了getStaff_work");
        System.out.println("员工信息是"+sss);
        try{
            if(sss!=null){
                staff_workslist = staff_workService.sel_staff_work(sss);   //传员工信息，查出一个员工并赋值
                //long staff_id1 = work.getStaff_id();                      //获取员工id
                System.out.println("员工信息是"+sss);
                return  new MassageJson(200,"请求成功",staff_workslist);
            }else {
                System.out.println("staff_id为空");
                return  new MassageJson(201,"请求失败",staff_workslist);
            }

        }catch (Exception e){
            e.printStackTrace();
        }

            return  new MassageJson(203,"请求失败",staff_workslist);

    }

    //改
//    @RequestMapping(value = "/updStaff_work", method = RequestMethod.POST)
//    public MassageJson updStaff_work(@RequestBody Staff_work staff_work){
//        System.out.println("接收到了==》"+staff_work);
//        int a = 0;
//        try{
//            a = staff_workService.upd_staff_work(staff_work);
//            System.out.println("a::::"+a);
//
//           System.out.println("在这里调用查询所有工作数据");
//            List<Staff_work> staff_works =null;
//
//            staff_works=staff_workService.staff_work_list_all();
//            if (a!=0){
//                return new MassageJson(200,"成功",staff_works);
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return new MassageJson(201,"错误");
//    }
//    @RequestMapping(value = "/updStaff_work", method = RequestMethod.POST)


//    改
    @PostMapping("/updStaff_work")
    public MassageJson updStaff_work(Staff_work staff_work){
        System.out.println("接收到了==》"+staff_work);
        int a = 0;
        try{
            a = staff_workService.upd_staff_work(staff_work);
            System.out.println("a::::"+a);

            if (a!=0){
                return new MassageJson(200,"成功",a);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return new MassageJson(201,"错误");
    }



    //查询所有
    @RequestMapping(value = "/staff_WorkList")
    public MassageJson staff_WorkList(){
        List<Staff_work> staff_worklist = null;
        try {
            staff_worklist = staff_workService.staff_work_list_all();
            System.out.println(staff_worklist);
            if (staff_worklist!=null){
                return new MassageJson(200,"成功",staff_worklist);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return new MassageJson(201,"错误",staff_worklist);
    }



}
